<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8" />
	<title>订单列表-{eyou:global name='web_name' /}</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
	<link href="{eyou:global name='web_cmspath'/}/favicon.ico" rel="shortcut icon" type="image/x-icon" />
	{eyou:static file="users/skin/css/bootstrap.min.css"/}
    {eyou:static file="users/skin/css/basic.css"/}
    {eyou:static file="users/skin/css/eyoucms.css"/}
    {eyou:static file="users/skin/css/shop.css"/}
	<!-- 新样式 2020-12-8 -->
	{eyou:static file="users/skin/css/element/index.css" /}
	{eyou:static file="users/skin/css/e-user.css" /}
    {eyou:include file="users/skin/css/diy_css.htm"/}
    
    {eyou:static file="/public/static/common/js/jquery.min.js"/}
    {eyou:static file="/public/plugins/layer-v3.1.0/layer.js"/}
    {eyou:static file="/public/static/common/js/tag_global.js"/}
</head>

<body>
{eyou:include file="users/users_header.htm" /}
	<!-- 头部信息 -->
	<div class="ey-header-status">
		<div class="header-status-l">
			<a href="javascript:history.go(-1)"><i class="el-icon-arrow-left"></i></a>
		</div> 
		<div class="header-status-m">{$eyou.field.title}</div> 
		<div class="header-status-r">
			<a href="{eyou:url link='user/Users/index' /}"><i class="el-icon-user"></i></a>
		</div>
	</div>
	<!-- 头部信息结束 -->
	<div class="h50"></div>

	<div class="ey-container">
		<div class="item-list">
			<a href="{eyou:url link='user/Shop/shop_cart_list'/}" class="item">
				<div class="item-l"> <i class="el-icon-shopping-cart-2"></i> 我的购物车</div>
				<div class="item-m tr"></div> 
				<div class="item-r"><i class="el-icon-arrow-right"></i></div>
			</a>
		</div>

		<div class="ey-con">
			<div class="ey-row">
				<!-- 中部 -->
				<div class="el-col-24">
					<!-- 查询栏 -->
					{eyou:spsearch id="search"}
						<form action="{$search.action}" method="get" >
						   {$search.hidden}
						   <div class="input-with-select el-input el-input-group el-input-group--append">
							   <input type="text" class="el-input__inner" name="keywords" value="{$Request.param.keywords}" placeholder="商品名称/订单号">
							   <div class="el-input-group__append">
								   <button type="submit" class="el-button el-button--default"> <i class="el-icon-search" aria-hidden="true"></i> </button>
							   </div>
							</div>
						</form>
					{/eyou:spsearch}
					 <!-- 查询栏结束 -->
				</div>

				<!-- 订单导航栏 -->
				<div class="el-col-24 oper-row mt20 mb20" >
				   	<!-- 订单导航栏 -->
					{eyou:spstatus id="field3"}
					<div class="el-button-group z_roll">
					   	<a class="el-button el-button--default el-button--small {if empty($field3.select_status) && $field3.access_action == 'shop_centre'}active{/if}" data-toggle="tab" href="{eyou:url link='user/Shop/shop_centre'/}"> 全部订单{eyou:if condition="0 != $field3.All"} <em>({$field3.All})</em> {/eyou:if}</a>

					  	<a class="el-button el-button--default el-button--small {eq name='$field3.select_status' value='dzf'}active{/eq}" data-toggle="tab" href="{eyou:url link='user/Shop/shop_centre' vars='select_status=dzf'/}"> 待付款{eyou:if condition="0 != $field3.PendingPayment"} <em>({$field3.PendingPayment})</em> {/eyou:if}</a>

					  	<a class="el-button el-button--default el-button--small {eq name='$field3.select_status' value='2'}active{/eq}" data-toggle="tab" href="{eyou:url link='user/Shop/shop_centre' vars='select_status=2'/}"> 待收货{eyou:if condition="0 != $field3.PendingReceipt"} <em>({$field3.PendingReceipt})</em> {/eyou:if}</a>

					   	<a class="el-button el-button--default el-button--small {eq name='$field3.select_status' value='3'}active{/eq}" data-toggle="tab" href="{eyou:url link='user/Shop/shop_centre' vars='select_status=3'/}"> 已完成{eyou:if condition="0 != $field3.Completed"} <em>({$field3.Completed})</em> {/eyou:if}</a>

					   	{gt name='$php_servicemeal' value='1'}
					   	<a class="el-button el-button--default el-button--small {if empty($field3.select_status) && $field3.access_action == 'after_service'} active {/if}" data-toggle="tab" href="{eyou:url link='user/Shop/after_service'/}"> 售后{eyou:if condition="0 != $field3.AfterService"} <em>({$field3.AfterService})</em> {/eyou:if}</a>
					   	{/gt}

				   	</div>
				   	{/eyou:spstatus}
				   	<!-- 订单导航栏结束 -->
				</div>
			</div>
		</div>
		
		<div class="el-col-24 clearfix" >
			
			<div class="goods-con">
				{eyou:empty name="$eyou.field.data"}
					<!-- 订单数据为空 -->
					<div class="el-row tc pt100 pb100 bgfff">
						<p class="mb10"><img id='litpic_img'  src="__PUBLIC__/static/common/images/null-data.png"/></p>
						<a href="{eyou:global name='web_cmsurl' /}" class="el-button el-button--default"><i class="el-icon-shopping-cart-full"></i> 马上去购物</a>
					</div>
				{eyou:else/}
				<!-- 获取订单数据列表 -->
				{eyou:sporderlist id="field" pagesize="10"}
				<div class="goods-item">
					<div class="item-top">
						<div class="item-top-l">订单号：<a href="{$field.OrderDetailsUrl}">{$field.order_code}</a></div>
						<div class="item-top-r red">{$field.order_status_name}</div>
					</div> 
					<div class="item-main">
						
						<!-- 获取订单商品 -->
						{eyou:spordergoods id="order_field"}
						<div class="item-con">
						    <div class="item-con-l">
								<a href="{$field.OrderDetailsUrl}"><img src="{$order_field.litpic}"></a>
							</div>
							<div class="item-con-m">
								<a href="{$field.OrderDetailsUrl}">
									{$order_field.product_name}
									{eyou:eq name="$order_field.has_deleted" value="1"}
										<span style="color: red;">{$order_field.msg_deleted}</span>
									{/eyou:eq}
								</a>
								{eyou:eq name="$field.order_status" value="3"}
								<div>
									{eyou:eq name="$order_field.has_deleted" value="0"}
										{eyou:eq name="$order_field.apply_service" value="1"}
	                                        <a href="{$order_field.ViewAfterSale}" style="color: red;">[查看售后]</a>
	                                    {eyou:else/}
	                                        <a href="{$order_field.ApplyService}" style="color: red;">[申请售后]</a>
	                                    {/eyou:eq}
	                                    {eyou:eq name="$order_field.is_comment" value="1"}
	                                        {eyou:eq name="$order_field.is_show" value="1"}
                                            <a href="{$order_field.arcurl}" style="color: red;" target="_blank">[查看评价]</a>
                                            {eyou:else/}
                                            <a href="JavaScript:void(0);" style="color: #a6a6a6;">[评价待审核]</a>
                                            {/eyou:eq}
	                                    {eyou:else/}
	                                        <a href="{$order_field.CommentProduct}" style="color: red;">[评价商品]</a>
	                                    {/eyou:eq}
	                                {/eyou:eq}
                                </div>
								{/eyou:eq}
							</div>
							<div class="item-con-r">
								<span class="price_flag">￥</span><span>{$order_field.product_price}</span>
								<p class="number">x{$order_field.num}</p>
							</div>
						</div>
						{/eyou:spordergoods}
					</div>
					<div class="item-bottom">
						<div class="item-bottom-l">
							总计：￥<span class="red">{$field.order_amount}</span>
						</div>
						<div class="item-bottom-r">
							<!-- <a class="el-button el-button--default el-button--small" href="{$field.OrderDetailsUrl}">详情</a> -->
							<!-- 订单状态判断，待付款 -->
							{eyou:eq name="$field.order_status" value="0"}
								{eyou:eq name="is_wechat" value='2'}
									<a href="{$field.PaymentUrl}" target="_blank" class="el-button el-button--primary el-button--small">
										立即付款
									</a>
								{eyou:else/}
									<a href="JavaScript:void(0);" class="el-button el-button--primary el-button--small" onClick="UpdatePayMethod('{$field.order_id}', '{$field.order_code}', 2);">
										立即付款
									</a>
								{/eyou:eq}
							{/eyou:eq}
							<!-- 待付款结束 -->
							
							<!-- 订单状态判断，待发货 -->
							{eyou:eq name="$field.order_status" value="1"}
								<a href="javascript:void(0);" class="el-button el-button--primary el-button--small" {$field.OrderRemind} >
									提醒发货
								</a>
							{/eyou:eq}
							<!-- 待发货结束 -->
							
							<!-- 订单状态判断，待收货 -->
							{eyou:eq name="$field.order_status" value="2"}
								<!-- 订单类型判断，普通订单可查看物流，虚拟订单无需查看物流 -->
								{eyou:eq name="$field.prom_type" value="0"}
									{eyou:eq name="$is_wechat" value="1"}
										<a href="{$field.MobileExpressUrl}" class="el-button el-button--primary el-button--small">物流查询</a>
									{eyou:else/}
										<a href="JavaScript:void(0);" class="el-button el-button--primary el-button--small" {$field.LogisticsInquiry}>物流查询</a>
									{/eyou:eq}
								{/eyou:eq}
								<!-- 订单类型判断结束 -->
								<a href="javascript:void(0)" class="el-button el-button--primary el-button--small" {$field.Confirm} >
									确认收货
								</a>
							{/eyou:eq}
							<!-- 待收货结束 -->

							<!-- 订单状态判断，已完成 -->
							{eyou:eq name="$field.order_status" value="3"}
                            <a href="javascript:void(0)" class="el-button el-button--primary el-button--small z-button--none">
								已完成
                            </a>
							{/eyou:eq}
							<!-- 已完成结束 -->
							
							<!-- 订单状态判断，已关闭 -->
							{eyou:eq name="$field.order_status" value="-1"}
							<a href="JavaScript:void(0);" class="el-button el-button--primary el-button--small mg05" mg05="">已关闭</a>
							{/eyou:eq}
							<!-- 已关闭结束 -->
						</div>
					</div>
				</div>
				<!-- 表单、JS隐藏域 -->
					{$field.hidden}
				{/eyou:sporderlist}
				<!-- 获取订单数据列表结束 -->
			 </div>
		</div>		 

		<!-- 分页输出 -->
		<div class="dataTables_paginate ">
			<ul class="pagination">
				{eyou:sppageorder listitem="index,end,pre,next" listsize="2"/}
			</ul>
		</div>
		<!-- 分页输出结束 -->
		{/eyou:empty}
	   <!-- 中部结束 -->

		<input type="hidden" id="unified_id">
		<input type="hidden" id="unified_number">
		<input type="hidden" id="transaction_type">
	</div>

<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
<script type="text/javascript">
    $(function(){
        wx.miniProgram.getEnv( function(res) {
            if(res.miniprogram) {
                // 小程序
                var i = 0;
                i = setInterval('AppletsPay()', 1000);
            }
        });
    });

    // 小程序查询
    function AppletsPay(){
        var unified_id       = $('#unified_id').val();
        var unified_number   = $('#unified_number').val();
        var transaction_type = $('#transaction_type').val();
        if (unified_id && unified_number && transaction_type) {
            $.ajax({
                url: "{eyou:url link='user/Pay/ajax_applets_pay'/}",
                data: {unified_id:unified_id, unified_number:unified_number, transaction_type:transaction_type},
                type:'post',
                dataType:'json',
                success:function(res){
                    if (1 == res.code) {
                        if (!res.data.mobile && !res.data.email) window.location.href = res.url;
                        if (res.data.mobile) SendMobile(res.data.mobile);
                        if (res.data.email) SendEmail(res.data.email);
                        window.location.href = res.url;
                    }
                }
            });    
        }
    }

	// 判断支付类型是否一致并且更新支付方式
    function UpdatePayMethod(unified_id, unified_number, transaction_type){
    	layer_loading('正在处理');
        $.ajax({
            url: "{eyou:url link='user/Pay/update_pay_method'/}",
            data: {unified_id:unified_id,unified_number:unified_number,pay_method:'WeChatInternal',transaction_type:transaction_type,order_source:2},
            type:'post',
            dataType:'json',
            success:function(res){
                layer.closeAll();
                if (0 == res.code) {
                	showErrorAlert(res.msg, 0);
                }else{
                    if (1 == res.data.is_gourl) {
                        window.location.href = res.url;
                    }else{
                        $('#unified_id').val(unified_id);
                        $('#unified_number').val(unified_number);
                        $('#transaction_type').val(transaction_type);
                        WeChatInternal(unified_id, unified_number, transaction_type);
                    }
                }
            }
        });
    }

	// 微信内部中进行支付
    function WeChatInternal(unified_id, unified_number, transaction_type)
    {   
        wx.miniProgram.getEnv( function(res) {
            if(res.miniprogram) {
                // 小程序
                wx.miniProgram.navigateTo({
                    url: '/pages/pay/pay?unified_id='+ unified_id +'&unified_number=' + unified_number + '&type=' + transaction_type
                });
            } else {
                // 微信端
                $.ajax({
                    url: "{eyou:url link='user/Pay/wechat_pay'/}",
                    data: {unified_id:unified_id,unified_number:unified_number,transaction_type:transaction_type},
                    type:'post',
                    dataType:'json',
                    success:function(res){
                        layer.closeAll();
                        if (1 == res.code) {
                            callpay(res.msg);
                        }else{
                        	showErrorAlert(res.msg, 0);
                        }
                    }
                });
            }
        });
    }

    //调用微信JS api 支付
    function jsApiCall(data)
    {
        WeixinJSBridge.invoke(
            'getBrandWCPayRequest',data,
            function(res){
                if(res.err_msg == "get_brand_wcpay_request:ok"){  
                    layer.msg('微信支付完成！', {time: 1000}, function(){
                        pay_deal_with();
                    });
                }else if(res.err_msg == "get_brand_wcpay_request:cancel"){
                	showErrorAlert('用户取消支付！', 0);
                }else{
                	showErrorAlert('支付失败，原因可能是订单号已支付！', 0);
                }  
            }
        );
    }
    
    // 微信内部支付时，先进行数据判断
    function callpay(data)
    {
        if (typeof WeixinJSBridge == "undefined"){
            if( document.addEventListener ){
                document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
            }else if (document.attachEvent){
                document.attachEvent('WeixinJSBridgeReady', jsApiCall); 
                document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
            }
        }else{
            jsApiCall(data);
        }
    }

    function pay_deal_with(){
        var unified_number   = $('#unified_number').val();
        var transaction_type = $('#transaction_type').val();
        $.ajax({
            url: "{eyou:url link='user/Pay/pay_deal_with'/}",
            data: {unified_number:unified_number,transaction_type:transaction_type},
            type:'post',
            dataType:'json',
            success:function(res){
                if (1 == res.data.status) {
                    if (!res.data.mobile && !res.data.email) window.location.href = res.url;
                    if (res.data.mobile) SendMobile(res.data.mobile);
                    if (res.data.email) SendEmail(res.data.email);
                    window.location.href = res.url;
                }
            }
        });
    }

    // 发送短信
    function SendMobile(result) {
        if (result) {
            $.ajax({
                url: result.url,
                data: result.data,
                type:'post',
                dataType:'json'
            });
        }
    }

    // 发送邮件
    function SendEmail(result) {
        if (result) {
            $.ajax({
                url: result.url,
                data: result.data,
                type:'post',
                dataType:'json'
            });
        }
    }
</script>
